package org.gd136.ce.script.impl;

import org.gd136.ce.script.Script;
import org.gd136.ce.script.ScriptStage;

public class SubScript extends Script {

	private static final String TAG = "#sub ";

	String paramName;
	String value;

	@Override
	public Script readScript(String scriptLine) {
		SubScript ss = null;
		if (scriptLine.startsWith(TAG)) {
			ss = new SubScript();
			String part = scriptLine.substring(TAG.length());
			int p = part.indexOf(' ');
			if (p < 1) {
				throw new IllegalArgumentException("sub 格式不正确! file[" + fileName
						+ "] line[" + lineNum + "]");
			}
			ss.paramName = part.substring(0, p);
			ss.value = part.substring(p + 1);
			ss.addToPoolAndLinkFrontScript();
		}
		return ss;
	}

	@Override
	public void execute(ScriptStage stage) {
		stage.subVariable(paramName, value);
	}

}
